const {db} = require("../../config/dbconfig");

// 添加评论
exports.addComments = async (req, res, next) => {
    const {articleId, content, authorId, parentCommentId} = req.body;
    db.query(
        'INSERT INTO Comments (article_id, content, author_id, parent_comment_id) VALUES (?, ?, ?, ?)',
        [articleId, content, authorId, parentCommentId],
        (error, results) => {
            if (error) {
                console.error('Error adding comment:', error);
                res.status(500).json({error: 'Error adding comment'});
            } else {
                res.status(201).json({code: '200', message: 'Comment added successfully', commentId: results.insertId});
            }
        }
    );
}
